package com.example.music.controller;

import com.example.music.domain.Orders;
import com.example.music.service.IOrdersService;
import com.example.music.util.AjaxResult;
import com.example.music.util.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Anonymous
@Api(tags = "音乐周边订单管理(224 魏川子)")
@RestController
@RequestMapping("/api/Orders")
public class OrdersController {
    @Autowired
    private IOrdersService ordersService;

    @ApiOperation(value = "获取所有订单的信息(224 魏川子)",notes = "获取所有订单的信息")
    @GetMapping("/list")
    public AjaxResult list(){
        return AjaxResult.success(ordersService.getOrders());
    }

    @ApiOperation(value = "根据id查找订单信息(224 魏川子)",notes = "根据id查找订单信息")
    @GetMapping("/{id}")
    public AjaxResult getOrdersById(@PathVariable("id") Long id){
        return AjaxResult.success(ordersService.selectOrdersById(id));
    }

    @ApiOperation(value = "新增订单信息 (224 魏川子)",notes = "新增一个订单信息")
    @PostMapping("/insert")
    public AjaxResult insertOrders(@RequestBody Orders orders){
        return AjaxResult.success(ordersService.insertOrders(orders));
    }

    @ApiOperation(value = "更新一个订单(224 魏川子)",notes = "更新一个订单信息")
    @PutMapping("/update")
    public AjaxResult updateOrders(@Validated  @RequestBody Orders orders){
        return AjaxResult.success(ordersService.updateOrders(orders));
    }

    @ApiOperation(value = "删除一个订单(224 魏川子)",notes = "删除一个订单")
    @DeleteMapping("/{id}")
    public AjaxResult deleteOrders(@PathVariable Long id){
        return AjaxResult.success(ordersService.deleteOrdersById(id));
    }
}
